﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace FCNS.Controls
{
    public partial class Line : Control
    {
        public Line()
        {
            InitializeComponent();
        }

        /// <summary>
        ///左、右、下、上、向右对角线、向左对角线
        /// </summary>
        public enum Directions
        {
            Left, Right, Down, Up, Diagonal_Right, Diagonal_Left
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            this.Border = this.Size.Height;
            base.OnSizeChanged(e);
        }
    
        private Color lColor = Color.Black;
        /// <summary>
        /// 线条的颜色
        /// </summary>
        [Category("FCNS"), Description("线条的颜色")]
        public override System.Drawing.Color ForeColor
        {
            get
            {
                return lColor;
            }
            set
            {
                lColor = value;
                this.Invalidate();
            }
        }

        private float intBorder = 1;
        /// <summary>
        /// 线条的粗细
        /// </summary>
        [Category("FCNS"), Description("线条的粗细"), DefaultValue(1)]
        public float Border
        {
            get
            {
                return intBorder;
            }
            set
            {
                intBorder = value;
              
            }
        }

        private Directions _directions;
        /// <summary>
        /// 箭头的方向
        /// </summary>
        [Category("FCNS"), Description("箭头的方向")]
        public Directions LDirections
        {
            set
            {
                _directions = value;
            }
            get
            {
                return _directions;
            }
        }

        private bool _isArrowAnchor = false;
        /// <summary>
        /// 是否显示箭头
        /// </summary>
        [Category("FCNS"), Description("是否显示箭头"), DefaultValue(false)]
        public bool IsArrowAnchor
        {
            set
            {
                _isArrowAnchor = value;
            }
            get
            {
                return _isArrowAnchor;
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            //创建线条
            using (Pen p = new Pen(this.ForeColor, this.Border))
            {
                Graphics g = this.CreateGraphics();
                p.DashStyle = DashStyle.Solid;
                if (this.IsArrowAnchor)
                {
                    p.EndCap = LineCap.ArrowAnchor;//显示箭头与否
                }
                switch (this.LDirections)
                {
                    case Directions.Right:
                        g.DrawLine(p, new Point(0, this.Height / 2), new Point(this.Width, this.Height / 2));
                        break;
                    case Directions.Left:
                        g.DrawLine(p, new Point(this.Width, this.Height / 2), new Point(0, this.Height / 2));
                        break;
                    case Directions.Down:
                        g.DrawLine(p, new Point(this.Width / 2, 0), new Point(this.Width / 2, this.Height));
                        break;
                    case Directions.Up:
                        g.DrawLine(p, new Point(this.Width / 2, this.Height), new Point(this.Width / 2, 0));
                        break;
                    case Directions.Diagonal_Right:
                        g.DrawLine(p, new Point(0, 0), new Point(this.Width, this.Height));
                        break;
                    case Directions.Diagonal_Left:
                        g.DrawLine(p, new Point(this.Width, this.Height), new Point(0, 0));
                        break;
                    default:
                        g.DrawLine(p, new Point(0, this.Height / 2), new Point(this.Width, this.Height / 2));
                        break;
                }
            }
            base.OnPaint(e);
        }

        bool printBorder = false;
        /// <summary>
        /// 是否打印边框
        /// </summary>
        [Category("FCNS"), Description("是否打印边框"), DefaultValue("False")]
        public bool PrintBorder
        {
            get
            {
                return printBorder;
            }
            set
            {
                printBorder = value;
            }
        }

    }
}